<template>
  <div class="app-container">
    <!--表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-select v-model="searchObj.type" clearable placeholder="请选择">
          <el-option label="会员登录数统计" value="login_num" />
          <el-option label="会员注册数统计" value="register_num" />
          <el-option label="路线浏览数统计" value="route_view_num" />
          <el-option label="路线数量计" value="route_num" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-date-picker
          v-model="searchObj.begin"
          type="date"
          placeholder="选择开始日期"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="searchObj.end"
          type="date"
          placeholder="选择截止日期"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-button
        :disabled="btnDisabled"
        type="primary"
        icon="el-icon-search"
        @click="showChart()"
      >查询</el-button>
    </el-form>

    <div class="chart-container">
      <div id="chart" class="chart" style="height:500px;width:100%" />
    </div>
  </div>
</template>
<script>
import echarts from "echarts"; //别忘了导入echarts
export default {
  data() {
    return {
      searchObj: {},
      btnDisabled: false,
      xData: [],
      yData: [],
    };
  },
  created() {},
  methods: {
    showChart() {
      this.$http({
        url: this.$http.adornUrl(`/statistic/daily/showData/${this.searchObj.type}/${this.searchObj.begin}/${this.searchObj.end}`),
        method: "get",
        params: this.$http.adornParams({}),
      }).then(({ data }) => {
        console.log(data.data)
        this.xData = data.data.dateList;
        this.yData = data.data.dataList;
        this.setChart();
      });
    },
    setChart() {
      //基于准备好的dom，初始化echarts实例
      this.chart = echarts.init(document.getElementById("chart"));
      // 指定图表的配置项和数据
      var option = {
        title: {
          text: "数据统计", //显示标题
        },
        tooltip: {
          trigger: "axis", //x坐标轴出发提示
        },
        // x轴是类目轴（离散数据）,必须通过data设置类目数据
        xAxis: {
          type: "category",
          data: this.xData,
        },
        // y轴是数据轴（连续数据）
        yAxis: {
          type: "value",
        },
        // 系列列表。每个系列通过 type 决定自己的图表类型
        series: [
          {
            // 系列中的数据内容数组
            data: this.yData,
            // 折线图
            type: "line",
          },
        ],
      };
      //将数据挂载到dom中
      this.chart.setOption(option);
    },
  },
};
</script>